Repository navigation
fix(context): skip source scan for classes without a base class - #11884
Open
zuhairkhalid229 wants to merge 1 commit into
Open
zuhairkhalid229 wants to merge 1 commit into
zuhairkhalid229 wants to merge 1 commit into
Conversation
describeInjectedArguments reads the class source and runs regular expressions to decide whether constructor injections are inherited. This also runs for a class with no base class, where nothing can be inherited, so applications that inspect many classes pay for it at startup. Check for a base class first and scan only when one exists. A class can be linked to a base class only through its prototype, and Reflect.getMetadata follows that link, so the check covers this case too. Results stay the same for such classes. Fixes loopbackio#11878 Signed-off-by: zuhairkhalid229 <zuhairkhalid229@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
describeInjectedArgumentsreads the class source and runs regular expressions to decide whether constructor injections are inherited. It does this even for a class with no base class, where nothing can be inherited.This adds a
hasBaseClasscheck, so the scan only runs when a base class exists.I did not use the guard from the issue on its own.
Reflect.getMetadataalso follows a base class that is linked only through.prototype, so checkingObject.getPrototypeOf(target)alone changes the result for those classes. For example, a class wired withObject.setPrototypeOf(A.prototype, Base.prototype)starts to inherit the injections ofBase.hasBaseClassuses the same rule asreflect-metadata, and a new test covers this case.Testing
.prototypestill gets[]. It fails with the guard from the issue.util.inheritsstill inherits its injections.@loopback/context: 711 passing.@loopback/core: 342 passing, 4 pending.I did not run the full monorepo test suite locally, and I did not re-measure the startup numbers from the issue.
Fixes #11878
Checklist
npm testpasses on your machine (ran@loopback/contextand@loopback/coreonly, see above)